﻿CREATE procedure AddOrderItem(@Amount decimal(10,2), @ItemDescription varchar(50), @Quantity int)
as
/*

declare @Amount decimal(10,2)
declare @ItemDescription varchar(50)
declare @Quantity int

set @Amount = 10.3
set @ItemDescription = 'whatever'
set @Quantity = 33

exec AddOrderItem @Amount, @ItemDescription, @Quantity

--select * from Service1Queue
--select *, cast(message_body as xml) from sys.transmission_queue
*/

begin
	declare @message xml
	set @message =''
	set @message = @message.query('
    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
	  <s:Header>
		<a:Action s:mustUnderstand="1">http://tempuri.org/IOrderProcessing/AddOrderItem</a:Action>
		<ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" 
			        CorrelationId="e00a084a-fb09-40ff-985b-28ae8c017729">f80571e9-c594-401f-bf14-c3a750eecf60</ActivityId>
		<a:To s:mustUnderstand="1">net.ssb://foo/Service1</a:To>
		<a:ReplyTo>
		  <a:Address>net.ssb://foo/Client1</a:Address>
		</a:ReplyTo>
	  </s:Header>
	  <s:Body>
		<AddOrderItem xmlns="http://tempuri.org/">
		  <item xmlns:b="http://schemas.datacontract.org/2004/07/TestClient" 
				xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
			<b:Amount>{ sql:variable("@Amount") }</b:Amount>
			<b:ItemDescription>{ sql:variable("@ItemDescription") }</b:ItemDescription>
			<b:Quantity>{ sql:variable("@Quantity") }</b:Quantity>
		  </item>
		</AddOrderItem>
	  </s:Body>
	</s:Envelope>')
    
    begin transaction
    declare @conv uniqueidentifier

	begin dialog conversation @conv
    from service Client1 to service 'Service1'
	on contract [DEFAULT] with encryption = off ;

	send on conversation @conv (cast(@message as varchar(max)));

    end conversation @conv;
    commit transaction;
    --select @message
end


